<template>
	<view class="container">
		<view class="intro-wrap">
			<view class="intro-title">登录之后更精彩</view>
			<view class="intro-text">与全世界精彩的经历、人和故事相遇</view>
		</view>

		<view class="login-wrap">
			<view class="item">
				<input type="text" placeholder="手机号" placeholder-style="color: #fff" v-model="userPhone" maxlength="11">
			</view>
			<view class="item">
				<input type="text" placeholder="验证码" placeholder-style="color: #fff" v-model="code">
				<view class="btn"><span @click="yz">{{sendText}}</span></view>
			</view>
			<view class="submit" @click="submit">验证并登录</view>
		</view>
		<view class="other-wrap">
			<view class="other-title">其他登录方式</view>
			<view class="other-icon">
				<view class="item">
					<image src="../../static/image/weChat.png" mode=""></image>
				</view>
				<view class="item">
					<image src="../../static/image/qq.png" mode=""></image>
				</view>
			</view>
			<view class="agreement-wrap">
				<label>
					<checkbox class="mycheck" value="cb" checked="true" />
				</label>
				<view class="agreement-text">我已同意《用户协议》</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				code: '',
				userPhone: '',
				sendText:'发送验证码',
				disSendSms:false,
				countDown:60
			}
		},
		onLoad() {

		},
		methods: {
			yz() {
				if(this.userPhone ){
					if(this.disSendSms==true || this.countDown!=60){
						return
					}
					else{
						uni.request({
							url: 'http://microtourism.natapp1.cc/api-user/verification-code',
							method: "POST",
							data: {
								"userPhone": this.userPhone
							},
							success: (res) => {
								// this.rm = res.data.data
								console.log(this.userPhone)
								console.log(res.data.code)
								console.log("验证码为："+res.data.data.numberCode)
								this.code = res.data.code
							},
							fail: (err) => {
								console.log(err)
							}
						})
						
					}
					let timerId=setInterval(()=>{
						this.disSendSms=true
						this.countDown--;
						this.sendText=this.countDown+"秒后重试"
						if(this.countDown<=0){
							clearInterval(timerId)
							this.sendText="发送验证码",
							this.countDown=60;
							this.disSendSms=false;
						}
					},1000)


				}

			},
			submit() {
				// uni.request({
				// 	url: 'http://microtourism.natapp1.cc/api-user/verification-code-check',
				// 	method: 'POST',
				// 	data: {
				// 		"userPhone": this.userPhone,
				// 		"verificationCode": this.code
				// 	},
				// 	success: (res) => {
				// 		console.log("数据为：" + res.data.code)
				// 		if (res.data.code != 200) {
				// 			console.log("登陆失败")
				// 			uni.showToast({
				// 				title: '账号或密码错误',
				// 				icon:"error",
				// 				duration: 2000
				// 			});
				// 			return
				// 		}
				// 		uni.setStorageSync('token', res.data.data.accessToken);
				 		console.log('asdf')
						uni.navigateTo({
							url: '../center/center',
							success: (res) => {
								console.log("登陆成功")
								uni.showToast({
									title: '登陆成功',
									icon:"success",
									duration: 2000
								});
							}
						})
				// 	},
				// 	fail: (err) => {
				// 		console.log(err)
				// 	}
				// })

			}
			// gt(phone){
			// 	uni.request({
			// 		url:'http://47.108.166.186:8988/userCenter/user/{phone}',

			// 		data:{

			// 		},
			// 		method:"GET",

			// 	})
			// }
		}
	}
</script>

<style>
	@import "./login.css";
</style>
